<?php
/**
 * Created by PhpStorm.
 * User: lyh
 * Date: 2017/5/10
 * Time: 10:24
 */
namespace Admin\Controller;
class OrderController extends CommonController{

    //订单首页
    public function index()
    {
        $status=I('post.status','4');
        $Model=M('Client_book');
        $detailModel=M('Userdetail');
        if(!isset($status) || $status=='4'){
            $map='';
        }else{
            $map['ordstatus']=$status;
        }
        $count= $Model->where($map)->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        if( !isset($status) ||$status=='4'){
            $list = $Model->order('starttime desc')->limit($Page->firstRow.','.$Page->listRows)->field('id,ordid,linkman,linkphone,amount,price,user_id,server_type,ordstatus')->select();
        }else{
            $map['ordstatus']=$status;
            $list=$Model->order('starttime desc')->where($map)->limit($Page->firstRow.','.$Page->listRows)->field('id,ordid,linkman,linkphone,amount,price,user_id,server_type,ordstatus')->select();
        }
        foreach($list as $key=>$value){
            $list[$key]['username']=$detailModel->where(array('userid'=>$value['user_id']))->getField('username');
        }

        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }
}